﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Rio.Applications.Web.Services;
using Rio.Framework.Localisation;
using Rio.Framework.Pages.AppCode.Helpers;
using Rio.Framework.Pages.AppCode.Helpers.Converter;
using Rio.Framework.Pages.ChildWindows;
using Rio.Framework.Pages.Context;
using Rio.Framework.Pages.Helpers.Converter;
using Rio.Framework.Pages.Manager;
using Rio.Framework.WCFService;
using Rio.Framework.WCFService.RioWcfServices;
using Telerik.Windows;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Data;
using NetBay.Core.Silverlight.Extensions;
using Document = NetBay.Core.BusinessEntities.Document;
using System.Text;

namespace Rio.Framework.Pages.Controls
{

    public delegate void LoadModificationSelectedDocumenthHandler(NetBay.Core.BusinessEntities.Document P_oDocument);

    public partial class ListDocumentControl
    {
        #region Attributs

        /// <summary>
        ///   Document list to fill the gridview
        /// </summary>
        private List<Document> m_oListDocuments;

        #endregion

        #region Events

        public event LoadModificationSelectedDocumenthHandler LoadModificationSelectedDocument;

        #endregion

        #region Properties

        /// <summary>
        ///   List of Documents in the gridview
        /// </summary>
        public List<NetBay.Core.BusinessEntities.Document> ListDocuments
        {
            get { return m_oListDocuments; }
            set
            {
                
                m_oListDocuments = value;
                LoadListDocument();

                // Disable delete button if user can't modify folder
                buttonDelete.Visibility = (GlobalWebContext.GetUserCanDelete(FolderTypeSelected))
                                              ? Visibility.Visible
                                              : Visibility.Collapsed;
            }
        }

        #endregion

        #region Constructors

        public ListDocumentControl()
        {
            InitializeComponent();

            InitLabel();

            //Add double click event at the gridview
            GridViewDoc.AddHandler(GridViewCellBase.CellDoubleClickEvent,
                                   new EventHandler<RadRoutedEventArgs>(OnCellDoubleClick), false);
        }

        public ListDocumentControl(List<NetBay.Core.BusinessEntities.Index> p_oIndexList)
            : this()
        {
            ListIndex = p_oIndexList;
        }

        #endregion

        private void OnCellDoubleClick(object sender, RadRoutedEventArgs args)
        {
            OnOpenDocumentClick();
        }

        private void LoadListDocument()
        {
            //Build a dictionnary list to bind folder and index value into the gridview
            List<Dictionary<string, Object>> L_oListRow = new List<Dictionary<string, Object>>();
            Dictionary<string, Object> L_oDict;

            //InitlabelNbrOfFolderResults();

            foreach (NetBay.Core.BusinessEntities.Document f in m_oListDocuments)
            {
                L_oDict = new Dictionary<string, Object>
                              {
                                  {"Identifier", f.Identifier},
                                  {"OriginalNameFile", f.OriginalNameFile},
                                  {"OriginalNameFileExtension", f.OriginalNameFileExtension}
                              };

                //For every value from ListValues, we have "ID;VALUE" for value list type index and user list type index, and we have "VALUE;VALUE" for the other index type
                //because for value list type index and user list type index we need the value to display and id for identify the value (for the consultation screen for exemple, to select the item in the combobox) 
                List<string> L_oIndexesValues = new List<string>(f.Folder.ListValues);
                List<NetBay.Core.BusinessEntities.Index> L_oIndexes =
                    new List<NetBay.Core.BusinessEntities.Index>(f.Folder.ListIndex);

                for (int i = 0; i < L_oIndexes.Count; i++)
                {
                    if (L_oIndexes[i].Type.Equals((int)IndexDomainServiceEnums.IndexType.Date))
                    {
                        if (L_oIndexesValues[i] != null
                            && L_oIndexesValues[i] != String.Empty)
                        {
                            L_oDict.Add("index" + L_oIndexes[i].Indentifier.ToString(), ToDateTime(L_oIndexesValues[i]));
                        }
                        else
                        {
                            L_oDict.Add("index" + L_oIndexes[i].Indentifier.ToString(), null);
                        }
                    }
                    else
                    {
                        L_oDict.Add("index" + L_oIndexes[i].Indentifier.ToString(), L_oIndexesValues[i]);
                    }
                }

                L_oListRow.Add(L_oDict);
            }

            //m_oListIndex = p_oIndexList;
            m_oSource = new QueryableCollectionView(L_oListRow);
            GridViewDoc.ItemsSource = m_oSource;
            DataPagerDoc.Source = m_oSource;

            // Display number of search result
            InitLabelNbrOfDocumetResult();
        }

        private void GridViewDoc_DataLoaded(object sender, EventArgs e)
        {
            GridViewDoc.UnselectAll();

            buttonDisplay.IsEnabled = false;
            buttonDelete.IsEnabled = false;
            buttonExport.IsEnabled = false;
        }

        /// <summary>
        ///   Translation
        /// </summary>
        public override void InitLabel()
        {
            base.InitLabel();

            labelColOriginalNameFile = Resx.GetLabel(ResxInfosDocument.ORIGIN_FILE);
            labelColAuthor = Resx.GetLabel(ResxInfosDocument.AUTHOR);
            labelColNote = Resx.GetLabel(ResxInfosDocument.NOTE);
            labelColPhotoCredit = Resx.GetLabel(ResxInfosDocument.PHOTO_CREDIT);
            labelColPublicationDate = Resx.GetLabel(ResxInfosDocument.PUBLICATION_DATE);
            labelMessageDeleteConfirmation = Resx.GetLabel(ResxCommon.DELETE_CONFIRMATION_DOCUMENT);

            buttonDisplay.Header = Resx.GetLabel(ResxCommon.DISPLAY);
            buttonDelete.Header = Resx.GetLabel(ResxCommon.DELETE);
            buttonExport.Header = Resx.GetLabel(ResxCommon.EXPORT);

            labelNbrOfDocumentResults = Resx.GetLabel(
                                                      ResxInfosDocument.NBR_OF_DOCUMENT_RESULT);

            DeleteItemContextMenu.Header = Resx.GetLabel(ResxCommon.DELETE);
            OpenDocumentContextMenu.Header = Resx.GetLabel(ResxCommon.DISPLAY);
            SaveDocumentContextMenu.Header = Resx.GetLabel(ResxCommon.SAVE_DOCUMENT);
            PrintMenuContextMenu.Header = Resx.GetLabel(ResxCommon.PRINT);
            SendMailContextMenu.Header = Resx.GetLabel(ResxCommon.SEND_BY_MAIL);
            ExportExcelContextMenu.Header = Resx.GetLabel(ResxCommon.EXPORT);
        }

        /// <summary>
        ///   Set Number of document result label
        /// </summary>
        private void InitLabelNbrOfDocumetResult()
        {
            LabelNbrOfDocumentResults.Visibility = System.Windows.Visibility.Visible;
            LabelNbrOfDocumentResults.Text = String.Format(labelNbrOfDocumentResults, m_oSource.ItemCount);
        }

        private void l_oCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            if (GridViewDoc.Items.Count
                == GridViewDoc.SelectedItems.Count)
            {
                GridViewDoc.UnselectAll();
            }
        }

        private void l_oCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            GridViewDoc.SelectAll();
        }

        /// <summary>
        ///   Inititialize folder search result GridView
        /// </summary>
        public void InitGridViewFolderSearch()
        {
            GridViewDoc.Columns.Clear();
            GridViewDoc.ItemsSource = null;

            CheckBox l_oCheckBox = new CheckBox();
            l_oCheckBox.Checked += l_oCheckBox_Checked;
            l_oCheckBox.Unchecked += l_oCheckBox_Unchecked;

            GridViewSelectColumn m_gvdcSelectedColumn = new GridViewSelectColumn { MinWidth = 30, Header = l_oCheckBox };
            GridViewDoc.Columns.Add(m_gvdcSelectedColumn);

            GridViewImageColumn l_oFileIcone = new GridViewImageColumn
            {
                UniqueName = "OriginalNameFileExtension",
                IsReadOnly = true,
                Header = string.Empty,
                Width = 40,
                ImageHeight = 32,
                ImageWidth = 32,
                DataMemberBinding = new Binding("[OriginalNameFileExtension]")
                {
                    Converter =
                        new ExtensionToImageConverter()
                }
            };
            GridViewDoc.Columns.Add(l_oFileIcone);

            GridViewDataColumn l_oColOriginalNameFile = new GridViewDataColumn
            {
                UniqueName = "OriginalNameFile",
                IsReadOnly = true,
                Header = labelColOriginalNameFile,
                MinWidth = 150,
                DataMemberBinding = new Binding("[OriginalNameFile]")
            };
            GridViewDoc.Columns.Add(l_oColOriginalNameFile);

            GridViewDataColumn L_gvdcDataColumn;
            foreach (NetBay.Core.BusinessEntities.Index t in ListIndex)
            {
                L_gvdcDataColumn = new GridViewDataColumn
                {
                    UniqueName = t.Indentifier.ToString(),
                    IsReadOnly = true,
                    Header = t.IndexLabel,
                    MinWidth = 150
                };

                //the prefix 'index' is need to bind correctly 
                //(Identifier is a numeric and the property bind has not to begin with a numeric, else we have a bad behavior with RadGridView such as disappearance filter or disabled grouping column)
                Binding bind = new Binding("[index" + t.Indentifier.ToString() + "]") { Converter = new IndexValueConverter() };

                L_gvdcDataColumn.DataType = GetIndexType(t);
                L_gvdcDataColumn.DataMemberBinding = bind;
                if (GetIndexType(t)
                    == typeof(DateTime?))
                {
                    L_gvdcDataColumn.DataFormatString = DateStringFormatterHelper.GetDateStringFormatter();
                }
                L_gvdcDataColumn.DataMemberBinding = bind;

                GridViewDoc.Columns.Add(L_gvdcDataColumn);
            }
        }

        public void UpdatePageSize(int P_iPageSize)
        {
            DataPagerDoc.PageSize = P_iPageSize;
        }

        private void GridViewDoc_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            if (GridViewDoc.SelectedItems.Count != 1)
            {
                buttonDisplay.IsEnabled = false;
                if (GridViewDoc.SelectedItems.Count == 0)
                {
                    buttonDelete.IsEnabled = false;
                    buttonExport.IsEnabled = false;
                }
                else
                {
                    buttonDelete.IsEnabled = true;
                    buttonExport.IsEnabled = true;
                }
            }
            else
            {
                buttonDisplay.IsEnabled = true;
                buttonDelete.IsEnabled = true;
                buttonExport.IsEnabled = true;
            }
        }

        #region Context Menu

        private void RadContextMenu_ItemClick(object sender, RadRoutedEventArgs e)
        {
            string L_oContextMenuName = ((RadMenuItem)e.OriginalSource).Name;

            switch (L_oContextMenuName)
            {
                case "DeleteItemContextMenu":
                    OnDeleteDocumentClick();
                    break;
                case "ExportExcelContextMenu":
                    OnExportClick();
                    break;
                case "OpenDocumentContextMenu":
                    OnOpenDocumentClick();
                    break;
                case "SaveDocumentContextMenu":
                    OnSaveDocumentClick();
                    break;
                case "PrintMenuContextMenu":
                    OnPrintMenuClick();
                    break;
                case "SendMailContextMenu":
                    OnSendMailClick();
                    break;
                default:
                    break;
            }
        }

        private void RadContextMenu_Opened(object sender, RoutedEventArgs e)
        {
            switch (GridViewDoc.SelectedItems.Count)
            {
                case 0:
                    {
                        ((RadContextMenu)sender).IsOpen = false;
                        break;
                    }
                case 1:
                    {
                        OpenDocumentContextMenu.IsEnabled = true;
                        SaveDocumentContextMenu.IsEnabled = (GlobalWebContext.GetUserCanPrint(FolderTypeSelected))
                                                                ? true
                                                                : false;
                        DeleteItemContextMenu.IsEnabled = (GlobalWebContext.GetUserCanDelete(FolderTypeSelected))
                                                              ? true
                                                              : false;
                        PrintMenuContextMenu.IsEnabled = (GlobalWebContext.GetUserCanPrint(FolderTypeSelected))
                                                             ? true
                                                             : false;
                        SendMailContextMenu.IsEnabled = (GlobalWebContext.GetUserCanSendMail(FolderTypeSelected))
                                                            ? true
                                                            : false;
                        break;
                    }
                default:
                    {
                        OpenDocumentContextMenu.IsEnabled = false;
                        SaveDocumentContextMenu.IsEnabled = false;
                        DeleteItemContextMenu.IsEnabled = (GlobalWebContext.GetUserCanDelete(FolderTypeSelected))
                                                              ? true
                                                              : false;
                        PrintMenuContextMenu.IsEnabled = (GlobalWebContext.GetUserCanPrint(FolderTypeSelected))
                                                             ? true
                                                             : false;
                        SendMailContextMenu.IsEnabled = (GlobalWebContext.GetUserCanSendMail(FolderTypeSelected))
                                                            ? true
                                                            : false;
                        break;
                    }
            }
        }

        #endregion

        #region Open Document

        /// <summary>
        ///   raise an event modification of selected document with the selected document in parameter
        /// </summary>
        /// <param name = "sender"></param>
        /// <param name = "e"></param>
        private void buttonDisplay_Click(object sender, RoutedEventArgs e)
        {
            OnOpenDocumentClick();
        }

        private void OnOpenDocumentClick()
        {
            if (GridViewDoc.SelectedItem != null)
            {
                Dictionary<string, Object> l_oDic = GridViewDoc.SelectedItem as Dictionary<string, Object>;
                if (l_oDic != null)
                {
                    NetBay.Core.BusinessEntities.Document L_oSelectedDocument =
                        m_oListDocuments.Where(f => f.Identifier == (long)l_oDic["Identifier"]).FirstOrDefault();
                    LoadModificationSelectedDocument(L_oSelectedDocument);
                }
            }
        }

        #endregion

        #region Delete Document

        /// <summary>
        ///   Event raised when the user clicks on the delete button
        /// </summary>
        /// <param name = "sender"></param>
        /// <param name = "e"></param>
        private void buttonDelete_Click(object sender, RoutedEventArgs e)
        {
            OnDeleteDocumentClick();
        }

        private void OnDeleteDocumentClick()
        {
            //List<Document> L_oSelectedDocuments = new List<Document>();
            List<long> L_oListDocumentId = new List<long>();
            if (GridViewDoc.SelectedItems != null
                && GridViewDoc.SelectedItems.Count > 0)
            {
                NetBay.Core.BusinessEntities.Document L_oDocument;
                foreach (Dictionary<string, Object> item in GridViewDoc.SelectedItems)
                {
                    Dictionary<string, Object> item1 = item;
                    L_oDocument =
                        m_oListDocuments.Where(f => f.Identifier == (long)item1["Identifier"]).FirstOrDefault();
                    if (L_oDocument != null)
                    {
                        //L_oSelectedDocuments.Add(L_oDocument);
                        L_oListDocumentId.Add(L_oDocument.Identifier);
                    }
                }

                MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow("",
                                                                             labelMessageDeleteConfirmation,
                                                                             MessageBoxButtons.YesNo,
                                                                             MessageBoxIcon.Question);
                L_oMessage.ShowDialog();

                L_oMessage.Closed += (s, ev) =>
                {
                    if (L_oMessage.Result
                        == MessageBoxResult.Yes)
                    {
                        DeleteDocuments(L_oListDocumentId);
                    }
                };
            }
        }

        /// <summary>
        ///   enable to delete a document
        /// </summary>
        /// <param name = "P_oListDocumentId"></param>
        private void DeleteDocuments(List<long> P_oListDocumentId)
        {
            try
            {
                var query = GlobalWebContext.BusinessEntitiesDomainContext.DeleteDocumentsQuery(P_oListDocumentId);
                GlobalWebContext.BusinessEntitiesDomainContext.Load(query, OnDeleteDocumentQueryCallback, P_oListDocumentId);
            }
            catch (Exception ex)
            {
                MessageBoxChildWindow L_oMessageDeleteDocument = new MessageBoxChildWindow("",
                                                                                           "Error : "
                                                                                           + Environment.NewLine
                                                                                           + ex.Message,
                                                                                           MessageBoxButtons.Ok,
                                                                                           MessageBoxIcon.Error);
                L_oMessageDeleteDocument.ShowDialog();
            }
        }

        private void OnDeleteDocumentQueryCallback(LoadOperation<NetBay.Core.BusinessEntities.ReturnObject> result)
        {
            if (result.Error != null)
            {

            }
            else
            {
                List<long> L_oDocumentId = (List<long>)result.UserState;
                foreach (long DocId in L_oDocumentId)
                {
                    long id = DocId;
                    foreach (Dictionary<string, Object> item in
                        m_oSource.Cast<Dictionary<string, Object>>().Where(item => (long)item["Identifier"] == id))
                    {
                        m_oSource.Remove(item);
                        break;
                    }
                }
                GridViewDoc.UnselectAll();

                InitLabelNbrOfDocumetResult();
            }
        }

        private void GridViewDoc_Deleting(object sender, GridViewDeletingEventArgs e)
        {
            e.Cancel = true;
            OnDeleteDocumentClick();
        }

        #endregion

        #region Export Excel

        private void buttonExport_Click(object sender, RoutedEventArgs e)
        {
            OnExportClick();
        }

        private void OnExportClick()
        {
            List<NetBay.Core.BusinessEntities.Document> L_oSelectedDocuments =
                new List<NetBay.Core.BusinessEntities.Document>();
            if (GridViewDoc.SelectedItems != null
                && GridViewDoc.SelectedItems.Count > 0)
            {
                L_oSelectedDocuments.AddRange(
                    GridViewDoc.SelectedItems.Cast<Dictionary<string, Object>>().Select(
                        item => m_oListDocuments.Where(f => f.Identifier == (long)item["Identifier"]).FirstOrDefault())
                        .Where(L_oDocument => L_oDocument != null));

                string data = Report.DocumentExport(L_oSelectedDocuments);
                SaveFileDialog sfd = new SaveFileDialog
                {
                    DefaultExt = "csv",
                    Filter = "CSV Files (*.csv)|*.csv|All files (*.*)|*.*",
                    FilterIndex = 1
                };

                try
                {
                    if (sfd.ShowDialog() == true)
                    {
                        using (Stream stream = sfd.OpenFile())
                        {
                            using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                            {
                                writer.Write(data);
                                writer.Close();
                            }
                            stream.Close();
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }

        #endregion

        #region Save Document

        private void OnSaveDocumentClick()
        {
            try
            {
                Dictionary<string, Object> l_oDic = GridViewDoc.SelectedItem as Dictionary<string, Object>;
                if (l_oDic != null)
                {
                    NetBay.Core.BusinessEntities.Document L_oDocumentToSave =
                        m_oListDocuments.Where(f => f.Identifier == (long)l_oDic["Identifier"]).FirstOrDefault();

                    //Build URI
                    WebClient webClient = new WebClient();
                    Uri baseUri = new Uri(webClient.BaseAddress);
                    UriBuilder uriBuilder = new UriBuilder(baseUri.Scheme, baseUri.Host, baseUri.Port);

                    string path = uriBuilder.ToString().TrimEnd('/');
                    string filename = "/Rio.Application.FileDownload.aspx?fp="
                                      +
                                      System.IO.Path.Combine(GlobalWebContext.ParameterStorage,
                                                   L_oDocumentToSave.RelativePath,
                                                   L_oDocumentToSave.ImageName) + "&name="
                                      + L_oDocumentToSave.OriginalNameFile;

                    VariableDomainContext L_vdcAppVirtualPath = new VariableDomainContext();
                    L_vdcAppVirtualPath.GetAppDomainAppVirtualPath(
                        str => System.Windows.Browser.HtmlPage.Window.Navigate(str.Value == "/"
                                                                                   ? new Uri(path + filename,
                                                                                             UriKind.Absolute)
                                                                                   : new Uri(
                                                                                         path + str.Value + filename,
                                                                                         UriKind.Absolute))
                        ,
                        null);
                }
            }
            catch (Exception)
            {
                ////Logger.Write("EXCEPTION : " + Environment.NewLine + ex.Message, Logger.Level.Error);
            }
        }

        #endregion

        #region Print Documents

        private void OnPrintMenuClick()
        {
            List<string> L_oDocumentToPrint = (from Dictionary<string, Object> item in GridViewDoc.SelectedItems
                                               select
                                                   m_oListDocuments.Where(f => f.Identifier == (long)item["Identifier"])
                                                   .FirstOrDefault()
                                                   into L_oSelectedDocument
                                                   select
                                                       System.IO.Path.Combine(GlobalWebContext.ParameterStorage,
                                                                    L_oSelectedDocument.RelativePath,
                                                                    L_oSelectedDocument.ImageName)).ToList();
            PrintDocumentsInPDFFormat(L_oDocumentToPrint);
        }

        /// <summary>
        /// Prints the documents in PDF format.
        /// </summary>
        /// <param name="l_oFileName">Name of the l_o file.</param>
        protected void PrintDocumentsInPDFFormat(List<string> l_oFileName)
        {
            if ((l_oFileName != null)
                && (l_oFileName.Count > 0))
            {
                SplashScreenManager.Wait(this);


                WCFServiceClient L_oWCFServiceClient = ServiceManager.GetRioWCFServiceClient();
                L_oWCFServiceClient.GetPrintableVersionOfDocumentFullPathCompleted +=
                    L_oWCFServiceClient_GetPrintableVersionOfDocumentFullPathCompleted;
                L_oWCFServiceClient.GetPrintableVersionOfDocumentFullPathAsync(
                    new ObservableCollection<string>(l_oFileName), ServiceManager.GetLicenseKey());

                BusinessEntitiesDomainContext l_oBecDC = new BusinessEntitiesDomainContext();
                var query = l_oBecDC.AddActionHistoricQuery((int)Constant.UserActions.IMPRESSION,
                                                            0,
                                                            0,
                                                            null,
                                                            l_oFileName.ToString(";"));
                l_oBecDC.Load(query);
            }
        }

        /// <summary>
        /// Handles the GetPrintableVersionOfDocumentFullPathCompleted event of the L_oWCFServiceClient control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rio.Framework.WCFService.RioWcfServices.GetPrintableVersionOfDocumentFullPathCompletedEventArgs"/> instance containing the event data.</param>
        private void L_oWCFServiceClient_GetPrintableVersionOfDocumentFullPathCompleted(object sender, GetPrintableVersionOfDocumentFullPathCompletedEventArgs e)
        {
            SplashScreenManager.Stop(this);
            string p_sFolder = e.Result.Value;

            string path =
                System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsoluteUri.Replace(
                    System.Windows.Browser.HtmlPage.Document.DocumentUri.LocalPath, String.Empty);
            const string filename = "/Rio.Application.OpenPDF.aspx";
            string l_szParameters = "?fld=" + System.Windows.Browser.HttpUtility.UrlEncode(p_sFolder);
            VariableDomainContext L_vdcAppVirtualPath = new VariableDomainContext();
            L_vdcAppVirtualPath.GetAppDomainAppVirtualPath(str => System.Windows.Browser.HtmlPage.Window.Navigate(
                str.Value == "/"
                    ? new Uri(
                          path + filename + l_szParameters,
                          UriKind.Absolute)
                    : new Uri(
                          path + str.Value + filename +
                          l_szParameters,
                          UriKind.Absolute),
                "_blank",
                "toolbar=no,location=no,status=no,menubar=no,resizable=yes,titlebar=no")
                                                           ,
                                                           null);
        }

        #endregion

        #region Send mail

        private void OnSendMailClick()
        {
            List<NetBay.Core.BusinessEntities.Document> l_oDocumentList =
                GridViewDoc.SelectedItems.Cast<Dictionary<string, Object>>().Select(
                    item => m_oListDocuments.Where(f => f.Identifier == (long)item["Identifier"]).FirstOrDefault()).
                    Where(L_oDocument => L_oDocument != null).ToList();
            EmailWindow l_oEmailWindow = new EmailWindow(null, l_oDocumentList, GlobalWebContext.ParameterStorage);
            l_oEmailWindow.ShowDialog();
        }

        #endregion

        public override void ClearResults()
        {
            if (m_oSource != null)
                m_oSource.Dispose();
        }
    }
}